package com.linkwedo.saas.project;

import java.util.List;

import com.linkwedo.saas.domain.Project;
import com.linkwedo.saas.domain.Target;

public class ProjectService {
	private ProjectDao projectDao;

	public ProjectDao getProjectDao() {
		return projectDao;
	}

	public void setProjectDao(ProjectDao projectDao) {
		this.projectDao = projectDao;
	}

	public Project getProject(Project project) {
		List<Project> uList = getProjectDao().findByExample(project);
		return uList.get(0);
	}
	
	public Project getProjectById(Integer projectId) {
		Project project= (Project)getProjectDao().findByProperty("id",projectId).get(0);
		return project;
	}
	
	public void save(Project transientInstance) {		
		try {
			getProjectDao().save(transientInstance);		
		} catch (RuntimeException re) {			
			throw re;
		}
	}
	
	public List findAll() {		
		try {
			return getProjectDao().findAll();
		} catch (RuntimeException re) {
			throw re;
		}
	}
	
	public void deleteById(Integer pid) {		
		try {
			Project transientInstance = getProjectDao().findById(pid);
			transientInstance.setId(pid);
			getProjectDao().delete(transientInstance);		
		} catch (RuntimeException re) {			
			throw re;
		}
	}
	
	public void disableById(Integer pid) {		
		try {
			Project transientInstance = getProjectDao().findById(pid);
			transientInstance.setId(pid);
			transientInstance.setStatus(new Integer(0));
			getProjectDao().merge(transientInstance);		
		} catch (RuntimeException re) {			
			throw re;
		}
	}
	
	public void enableById(Integer pid) {		
		try {
			Project transientInstance = getProjectDao().findById(pid);
			transientInstance.setStatus(new Integer(1));
			getProjectDao().merge(transientInstance);		
		} catch (RuntimeException re) {			
			throw re;
		}
	}
	
}
